import {
  ApiBody,
  ApiCreatedResponse,
  ApiNotFoundResponse,
  ApiOkResponse,
  ApiOperation,
  ApiParam,
  ApiTags,
} from '@nestjs/swagger';
import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Patch,
  Post,
} from '@nestjs/common';
import { Public } from '../common/isPublic';
import { CreateSortDto } from './dto/create-sort.dto';
import { UpdateSortDto } from './dto/update-sort.dto';
import { SortService } from './sort.service';

@ApiTags('文章分类')
@Controller('sort')
@Public()
export class SortController {
  constructor(private readonly sortService: SortService) {}

  @Post()
  @ApiOperation({ summary: '创建一个新的分类' })
  @ApiBody({ type: CreateSortDto })
  @ApiCreatedResponse({ description: '分类创建成功', type: CreateSortDto })
  create(@Body() createSortDto: CreateSortDto) {
    return this.sortService.create(createSortDto);
  }

  @Get()
  @ApiOperation({ summary: '获取所有分类' })
  @ApiOkResponse({ description: '分类列表获取成功', type: [CreateSortDto] })
  findAll() {
    return this.sortService.findAll();
  }

  @Get(':id')
  @ApiOperation({ summary: '根据ID获取单个分类' })
  @ApiParam({ name: 'id', description: '分类ID' })
  @ApiOkResponse({ description: '分类信息获取成功', type: CreateSortDto })
  @ApiNotFoundResponse({ description: '未找到分类' })
  findOne(@Param('id') id: string) {
    return this.sortService.findOne(id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '更新一个分类' })
  @ApiParam({ name: 'id', description: '分类ID' })
  @ApiBody({ type: UpdateSortDto })
  @ApiOkResponse({ description: '分类更新成功', type: UpdateSortDto })
  update(@Param('id') id: string, @Body() updateSortDto: UpdateSortDto) {
    return this.sortService.update(id, updateSortDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除一个分类' })
  @ApiParam({ name: 'id', description: '分类ID' })
  @ApiOkResponse({ description: '分类删除成功' })
  @ApiNotFoundResponse({ description: '未找到分类' })
  remove(@Param('id') id: string) {
    return this.sortService.remove(id);
  }
}
